goodsFormatter = function (value, row, index) {
    return ['<a class="find" href="javascript:void(0)" >查看商品详情</i></a>' +
    '&nbsp;&nbsp;&nbsp;' +
    '<a class="yesUpper" href="javascript:void(0)" style="color: #00ca6d">上架</a>' +
    '&nbsp;&nbsp;&nbsp;' +
    '<a class="remove" href="javascript:void(0)" style="color: red">删除</a>' +
    '&nbsp;&nbsp;&nbsp;'
    ].join('');
};

window.goodsEvent = {
    'click .find': function (e, value, row, index) {
        showModel("show-div", function () {
            $("#oldPrice").val(row.oldPrice);
            $("#price").val(row.price);
            $("#bagging").val(row.bagging);
            $("#stock").val(row.stock);
            $("#detail").val(row.goodsDetail);
            console.log(row)
            if (row.params == 1) {
                var p = '支持';
            } else {
                var p = '不支持';
            }
            $("#params").val(p);

            var img = row.images;
            var imgs = "";
            if (img == null || img == "") {
                var an = '<image src=' + $().AbsUrlParse("/static/images/no.png") + ' style="width:150px;height:150px" onclick="enlargeImage(this)"/>';
                $("#showimages").html(an);
            } else {
                var imgArr = img.split(",");
                for (var i = 0; i < imgArr.length; i++) {
                    if (imgArr[i] != "" || imgArr[i] != null) {
                        var imgUrl = File_Download_Url + imgArr[i];
                        imgs += '<image src=' + imgUrl + ' style="width:150px;height:150px" onclick="enlargeImage(this)"/>&nbsp;&nbsp;';
                    }
                }
                $("#showimages").html(imgs);
            }
        })
    },
    'click .yesUpper': function (e, value, row, index) {
        comment.showOperationTips("确定该商品上架吗？", function () {
            $.post($().AbsUrlParse("/web/goods/yesUpper"), {id: row.id}, function (data) {
                if (data.state == true) {
                    if (data.res.code == 40000) {
                        hint("操作成功,该产品已经上架");
                        var table = $('#table');
                        table.bootstrapTable('refresh');
                    } else {
                        hint(data.res.msg);
                    }
                } else {
                    hint(data.msg);
                }

            });
        })
    },
    'click .remove': function (e, value, row, index) {
        comment.showOperationTips("你确定删除该商品吗？", function (data) {
            $.post($().AbsUrlParse("/web/goods/deleteGoodsById"), {id: row.id}, function (data) {
                if (data.state == true) {
                    if (data.res.code == 40000) {
                        hint("操作成功,该产品已经删除");
                        var table = $('#table');
                        table.bootstrapTable('refresh');
                    } else {
                        hint(data.res.msg);
                    }
                } else {
                    hint(data.msg);
                }
            });
        })
    }

}

isSpecialFormatter = function (value, row, index) {
    var myDate = new Date();
    var year = myDate.getFullYear();    //获取完整的年份(4位,1970-????)
    var month = myDate.getMonth() + 1;       //获取当前月份(0-11,0代表1月)
    var day = myDate.getDate();        //获取当前日(1-31)
    var hous = myDate.getHours();       //获取当前小时数(0-23)
    var minutes = myDate.getMinutes().toString();   //获取当前分钟数(0-59)
    if (minutes.length < 2) {
        var sec = "0" + minutes;
    } else if (minutes.length == 2) {
        var sec = minutes;
    }
    var seconds = myDate.getSeconds();    //获取当前毫秒数(0-999)

    var time = year + "-" + month + "-" + day + " " + hous + ":" + sec + ":" + seconds; //系统时间
    var exTime = row.expirationTime; //特价时间
    if (exTime != null) {
        var num = Date.parse(exTime);
    }
    var da = Date.parse(time);
    if (num - da > 0) {
        return "<span style='color:#00ca6d;'>是</span>";
    } else if (exTime == null) {
        return "<span style='color:blue;'>否</span>";
    } else if (num - da <= 0) {
        return "<span style='color: red'>特价时间到期</span>";
    }
};


headPicFormatter = function (value, row, index) {
    var img = row.headPic;
    var imgs = img.split(",");
    var imgUrl = "";
    if (img != null && img != "") {
        imgUrl = File_Download_Url + imgs[0];
        return '<image src=' + imgUrl + ' style="width:80px;height:80px" onclick="enlargeImage(this)"/>';
    }
    if (img == null || img == "") {
        return '<image src=' + $().AbsUrlParse("/static/images/no.png") + ' style="width:80px;height:80px" onclick="enlargeImage(this)"/>'
    }
};


//查询商品
bindClick("#goodsSelect", function () {
    var goodsName = $("input[name=goodsName1]").val();
    var busName = $("#busName").val();
    var url = $().AbsUrlParse("/web/goods/noUpperList?goodsName=" + goodsName + "&busName=" + busName);
    $("#table").bootstrapTable("refresh", {url: url});
});

expirationTime = function (value, row, index) {
    var expirationTime = row.expirationTime;
    if (expirationTime == null) {
        return "<span>该商品不是特价商品</span>";
    } else {
        return ['<span> ' + expirationTime + '</span>'].join();
    }
};

function enlargeImage(value) {
    showModel("detailImage-div", function () {
        var imgs = '<image src=' + value.src + ' style="height:500px" />';
        $("#image").html(imgs);
    })
}
